#include<iostream>
#include<algorithm>
#include<vector>

class Solution
{
    public:
    int maxSubArray(const std::vector<int>& nums)
    {
        int Max = nums[0];
        if(nums.size() == 0)
        {
            return 0;
        }
        std::vector<int>p(nums.size());
        p[0] = nums[0];
        for(int i = 1;i < nums.size();i++)
        {
            p[i] = std::max(p[i-1] + nums[i],nums[i]);
            Max = std::max(p[i],Max);
        }
        return Max;
    }
};